package cate.game.event.adventure;

import cate.game.event.GameEventListener;
import cate.game.role.Role;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AdventurePassedIdChangeListener implements GameEventListener<AdventurePassedIdChangeEvent> {
    @Override
    public void onEvent(AdventurePassedIdChangeEvent gameEvent) {
        Role role = gameEvent.role;
        //排行榜
        role.getHistory().action.adventureCombatNum(gameEvent.passedId);
        //最好只配确定受主线影响的功能，不确定的话还是都写
        safe(() -> role.getFarm().tower.checkOpen(), "farm tower checkOpen");
        // 检测功能开启
        safe(() -> role.getActivity().checkOpen(), "activity checkOpen");
    }

    private void safe(Runnable runnable, String description) {
        try {
            runnable.run();
        } catch (Exception e) {
            log.error(description + "报错拉");
        }
    }
}
